<include file="Index:header" />
<style>
    .view {
        width: 100%;
    }
</style>
<!--左侧菜单-->
<!--<div class="col-md-2" id="left-menu">
    <ul class="nav nav-pills nav-stacked">
        <li style="display:none;" role="presentation"   ><a href="__APP__/"><i class="glyphicon glyphicon-home"></i>控制台</a></li>
        <li role="presentation" class="active"  ><a href="__APP__/Capacity/learnstyles"><i class="glyphicon glyphicon-warning-sign"></i>问卷调查</a></li>
        <li style="display:none;" role="presentation" ><a href="__APP__/Capacity/potential"><i class="glyphicon glyphicon-warning-sign"></i>多元潜能</a></li>
    </ul>
</div>-->

<div class="col-md-10" id="contents">
    <!--测试简介-->
    <div class="test-desc">
        <div class="alert alert-success" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
            <p>学校教学管理部门服务满意度问卷调查</p>
        </div>
        <div class="lb_introduce_text">
            <p>敬爱的师生： </p>
            <p>
                为了更好的服务全校师生。

            </p>
            <p>
                为了充分了解师生对我校教育教学和管理工作的总体评价和认可程度。
            </p>
            <p>
                特地开展此次的教学管理部门服务满意度问卷调查.
            </p>
            <p>
                这次调查共十四道选择题，您只需要从 a,b,c,d 中间选择一个，最后一道题，您可以写下您对我校教学管理工作应该改进之处。
            </p>
        </div>
        <br>
        <br>
        <a type="btn" class="btn btn-default btn-block btn-success start-test">点击开始测试</a>
    </div>
    <include file="Index:testcontent" />
</div>
<include file="Index:footer" />
<script>
    var num = 0; //表示第一道题  
    var list = new Array();
    /*获取浏览器指纹*/
    var fingerprint = new Fingerprint().get();

    /*获取浏览器指纹结束*/

    $(function () {
        $(".pageCount").html(learnstyles.length);
        //点击开始测试
        $(".start-test").click(function () {
            $(".test-desc").hide();
            $(".test-content").show();
            $(".test-title").html(learnstyles[num].title);
            var question = showQuestion(num);
            $(".test-questions").html(question);
        });
        //下一道题
        $(".start-next-test").click(function () {
             //检测是否选中
            var val=$('input:radio[name="result"]:checked').val();
            
            var title = learnstyles[num].title;
            if (num >= learnstyles.length - 1) {
                var results = $(".view").val();
                list.push({'title':title,'value':results});
            }else{
                if(val==null){
                    alert("请选择题目!");
                    return false;
                }
                list.push({'title':title,'value':val});
            }
            
            nextQuestion();
        });
        //上一道题
        $(".start-last-test").click(function () {
            lastQuestion();
        });
    });

    function nextQuestion() {
        if (num >= learnstyles.length - 1) {
            console.log(list);
            $.ajax({
                url: "{:U('index/adminajax')}",
                data: {
                    'name': fingerprint,
                    'list': list,
                },
                dataType:'json',
                type: "post",
                success: function (data) {
                    if (data == 1) {
                        // alert('用户名错误');
                        alert("恭喜你，你已经回答完毕！");
                    }
                    if (data == 2) {
                        alert("数据异常，请刷新重新提交！");
                    }
                    if (data == 3) {
                        alert("请勿重复提交！");
                    }
                    window.location.reload();
                }
            });
          
        }else{
           
            num = num + 1;
            $(".test-title").html(learnstyles[num].title);
            var question = showQuestion(num);
            $(".test-questions").html(question);
        }

    }
    function lastQuestion() {
        if (num == 0) {
            alert("第一题了");
            return;
        }
        num = num - 1;
        $(".test-title").html(learnstyles[num].title);
        var question = showQuestion(num);
        $(".test-questions").html(question);
    }

    function selectResult(ele) {
        console.log($($(ele).siblings()));
        console.log($(ele).children());
        $(ele).children().prop('checked', true);
        $($(ele).siblings()).children().prop("checked", false);
    }

    //显示问题
    function showQuestion(num) {
        $(".pageNow").html(num + 1);
        if (num == 14) {
            $(".start-next-test").html("确认提交");
            question = "<textarea class='view list-group-item' name='result' ></textarea>";
        } else {
            var results = learnstyles[num].result;
            var question = "";
            for (var i in results) {
                question = question + "<a class='list-group-item' onClick='selectResult(this)'><input type='radio' name='result' class='result' value='" + results[i] + "'>" + results[i] + "</a>";
            }
        }
        return question;
    }

</script>